package Demo;
// 线程安全问题
class Test1{
    public  int count = 0;
    public synchronized void add(){
        count++;
    }
}
public class Demo5 {

    public static void main(String[] args) throws InterruptedException {
        Test1 test = new Test1();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                test.add();
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                test.add();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(test.count);
    }
}
